﻿using Microsoft.EntityFrameworkCore;
using ZeroSum.Domain.UnitOfWork;

namespace ZeroSum.Extend.EFCore.MySql.EntityFrameworks;

/// <summary>
///     EFCore版本的工作单元实现
/// </summary>
public class EFCoreUnitOfWork<TDbContext> : IUnitOfWork
    where TDbContext : DbContext
{
    private readonly TDbContext _dbContext;

    public EFCoreUnitOfWork(TDbContext dbContext)
    {
        _dbContext = dbContext;
    }

    public void SaveChanged()
    {
        _dbContext.SaveChanges();
    }

    public async Task SaveChangesAsync()
    {
        await _dbContext.SaveChangesAsync();
    }
}